// /////////////////////////////////////////////////////////////////////////////
//
// Name:            ReferenceCounted.cpp
// Author:          Michael Bartsch (ZCCdark203)
//
// Desc :           This class provides reference counting through the methods
//                  grab() and drop(). Most objects with the framework are
//                  derived from ReferenceCounted, and so they are reference
//                  counted.
//
// License:         Copyright (C) 2009 Michael Bartsch and Contributors
//
//                  This program is free software: you can redistribute it
//                  and/or modify it under the terms of the zlib/libpng License.
//                  See main.cpp for conditions of distribution and use.
//
// /////////////////////////////////////////////////////////////////////////////

// Include files
#include "ReferenceCounted.h"


// ReferenceCounted class
// ReferenceCounted constructor.
ReferenceCounted::ReferenceCounted()
: mRefCount(1)
{
}

// ReferenceCounted deconstructor.
ReferenceCounted::~ReferenceCounted()
{
}

// Gets the reference count.
s32 ReferenceCounted::getReferenceCount()
{
    return mRefCount;
}

// Increases the reference counter.
void ReferenceCounted::grab()
{
    ++mRefCount;
}

// Decreases the reference counter.
void ReferenceCounted::drop()
{
    if(--mRefCount == 0)
      delete this;
}

// End of File
